package com.guigu.qingcheng.systemservice.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.guigu.qingcheng.pojo.system.TbMenu;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@Mapper
public interface TbMenuMapper extends BaseMapper<TbMenu> {
    @Select("SELECT * FROM tb_menu WHERE id IN(\n" +
            "SELECT menu_id FROM tb_resource_menu WHERE resource_id IN (\n" +
            "SELECT resource_id FROM tb_role_resource WHERE role_id IN (\n" +
            "SELECT role_id FROM tb_admin_role WHERE admin_id IN (\n" +
            "SELECT id FROM tb_admin WHERE login_name='${admin}'\n" +
            ")\n" +
            ")\n" +
            ")\n" +
            ")\n" +
            "UNION\n" +
            "SELECT * FROM tb_menu WHERE id IN(\n" +
            "SELECT parent_id FROM tb_menu WHERE id IN(\n" +
            "SELECT menu_id FROM tb_resource_menu WHERE resource_id IN (\n" +
            "SELECT resource_id FROM tb_role_resource WHERE role_id IN (\n" +
            "SELECT role_id FROM tb_admin_role WHERE admin_id IN (\n" +
            "SELECT id FROM tb_admin WHERE login_name='${admin}'\n" +
            ")\n" +
            ")\n" +
            ")\n" +
            ")\n" +
            ")\n" +
            "UNION\n" +
            "SELECT * FROM tb_menu WHERE id IN (\n" +
            "SELECT parent_id FROM tb_menu WHERE id IN(\n" +
            "SELECT parent_id FROM tb_menu WHERE id IN(\n" +
            "SELECT menu_id FROM tb_resource_menu WHERE resource_id IN (\n" +
            "SELECT resource_id FROM tb_role_resource WHERE role_id IN (\n" +
            "SELECT role_id FROM tb_admin_role WHERE admin_id IN (\n" +
            "SELECT id FROM tb_admin WHERE login_name='${admin}'\n" +
            ")\n" +
            ")\n" +
            ")\n" +
            ")\n" +
            ")\n" +
            ")")
    List<TbMenu> findList2(@Param("admin")String admin);
}
